package com.cmy.array;

import java.util.Arrays;

public class Sorting {
    public static void main(String[] args) {
        int[] a = {2,5,456,1,3,7,15,6};
        BubbleSrt(a);
        System.out.println(Arrays.toString(a));
    }

    public static int[] BubbleSrt(int[] a){
        for(int i =0;i < a.length-1;i++){
            boolean flag = false;//通过标识符减少无意义排序
            for (int j=0;j<a.length-i-1;j++){
                if (a[j]>a[j+1]){
                    int temp;
                    temp = a[j];
                    a[j] = a[j+1];
                    a[j+1] = temp;
                    flag = true;
                }
            }
            if (flag ==false){
                break;
            }

        }
        return a;
    }
}

    